﻿using System;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace HexPixel
{
	public partial class MainForm : Form
	{
		private string m_strHexData;
		private PixelSize m_ePixelType = PixelSize.BIT_32;

		public MainForm()
		{
			InitializeComponent();

			this.comboBoxPixelFormat.SelectedIndex = (int)m_ePixelType;
		}

		private void GetHexDataFromTextBox()
		{
			m_strHexData = this.textBoxHexData.Text;
		}

		private void buttonView_Click(object sender, EventArgs e)
		{
			try
			{
				int nImageWidth = Int32.Parse(this.textBoxImageWidth.Text);
				if (nImageWidth < 0)
				{
					MessageBox.Show("Width value is under 0.\nSet default 1.");
					nImageWidth = 1;
				}

				GetHexDataFromTextBox();

				Color[] cc = HexTextParser.Parse(m_strHexData, m_ePixelType);

				if (cc != null)
				{
					Forms.PixelViewForm f = new Forms.PixelViewForm();
					f.SetPixelData(cc, nImageWidth, m_ePixelType);
					f.Show();
				}
				else
				{
					MessageBox.Show("Empty data.");
				}
			}
			catch (Exception except)
			{
				MessageBox.Show(except.Message);
				return;
			}
		}

		private void comboBoxPixelFormat_SelectedIndexChanged(object sender, EventArgs e)
		{
			m_ePixelType = (PixelSize)this.comboBoxPixelFormat.SelectedIndex;
		}
	}
}
